﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using SubSonic;


namespace Business
{
     public class ProjectTaskDetails
    {
        public static List<ProjectStatusTaskType> GetAllSteps(Guid contractId)
        {
            TblContractCollection contractCollection = new TblContractCollection();
            TblTaskCollection taskCollection = new TblTaskCollection();
            List<ProjectStatusTaskType> output = new List< ProjectStatusTaskType >();
            ProjectStatusTaskType status = new ProjectStatusTaskType();
            contractCollection.LoadAndCloseReader( TblContract.FetchByParameter( TblContract.Columns.Id , Comparison.Equals , contractId ));
            if(contractCollection.Count == 1)
            {
                taskCollection.LoadAndCloseReader(TblTask.FetchByParameter(TblTask.Columns.ContractId, Comparison.Equals, contractId));
                foreach ( var task in taskCollection )
                {
                    status = new ProjectStatusTaskType(contractCollection[0] , task);
                    output.Add(status);
                }
            }
            output.Sort( Business.CommonCalculations.SortSteps );
            return output;
        }
//         public static List<ProjectStatusTaskType> GetAllStepsbonyadshahrestan(Guid contractId)
//        {
//            TblContractCollection contractCollection = new TblContractCollection();
//            TblTaskCollection taskCollection = new TblTaskCollection();
//            List<ProjectStatusTaskType> output = new List< ProjectStatusTaskType >();
//            ProjectStatusTaskType status = new ProjectStatusTaskType();
//            contractCollection.LoadAndCloseReader( TblContract.FetchByParameter( TblContract.Columns.Id , Comparison.Equals , contractId ));
//            if(contractCollection.Count == 1)
//            {
//                taskCollection.LoadAndCloseReader(TblTask.FetchByParameter(TblTask.Columns.ContractId, Comparison.Equals, contractId,OrderBy.Desc()));
//                taskCollection.RemoveAt(7);
//                taskCollection.RemoveAt(8);
//                taskCollection.RemoveAt(9);
//                taskCollection.RemoveAt(10);
//                taskCollection.RemoveAt(11);
//                taskCollection.RemoveAt(12);
////taskCollection.RemoveAt(13);
////taskCollection.RemoveAt(14);
////taskCollection.RemoveAt(15);
////taskCollection.RemoveAt(16);
////taskCollection.RemoveAt(17);




//                foreach ( var task in taskCollection )
//                {
//                    status = new ProjectStatusTaskType(contractCollection[0] , task);
//                    output.Add(status);
//                }
//            }
//            output.Sort( Business.CommonCalculations.SortSteps );
//            return output;
//        }
    }
}
